<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Auth\Authenticatable;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use App\Exceptions\AuthenticatesLogout;
class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers,AuthenticatesLogout{
        //如果添加到同一个class的两个trait中有相同的函数名，且没有明确的进行处理，将产生一个错误。为了解决同一个类中两个trait中的同名函数冲突，需要用insteadof操作符来选择正确的函数。因为方法的唯一性和排他性，‘as’操作符允许冲突之后解决内部冲突的问题
        AuthenticatesLogout::logout insteadof AuthenticatesUsers;
    }

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/admin';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {

        $this->middleware('guest.admin')->except('logout');
    }

    /*
     * 显示后台登录模板
     * */
    public function showLoginForm()
    {

       return view('admin.login');
    }

    /*
     * 使用admin guard
     * */
    protected function guard()
    {
        return auth()->guard('admin');
    }
    /*
     * 重写验证时使用的用户名字段
     * */
    public function username()
    {
        return 'name';
    }


}
